--  ---------------------------------------------------------------------------
--  @File: symbol_table.adb
--
--  @Project: LiberAda
--  @Version: 1.0
--  @Created: 2009-10-08
--  @Author:  Ivan Bogicevic
--
--  @Description:
--
--  @Modifications:
--
--  ---------------------------------------------------------------------------
with Ada.Strings.Unbounded;
with Ada.Containers.Vectors;

with Symbol;
with Part;

package Symbol_Table is

   package ASU renames Ada.Strings.Unbounded;

   package String_Vector is new
      Ada.Containers.Vectors (Index_Type => Natural,
                              Element_Type => ASU.Unbounded_String,
                              "=" => ASU."=");

   type Part_Pointer is access Part.Part_Type;

   package Parts_Vector is new
      Ada.Containers.Vectors (Index_Type => Natural,
                              Element_Type => Part_Pointer,
                              "=" => "=");

   --  ------------------------------------------------------------------------
   --  @Function: Add_Symbol
   --  @Description: Adds a symbol to the symbol table
   --  @Parameter:
   --    +Symb: The symbol to be added
   procedure Add_Symbol (Symb : Symbol.Symbol_Type);

   --  ------------------------------------------------------------------------
   --  @Function: Add_Link
   --  @Description: Adds a link to a symbol to the symbol table
   --  @Parameter:
   --    +Link: The link to be added (the symbol is unknown yet)
   procedure Add_Link (Link : ASU.Unbounded_String);

   --  ------------------------------------------------------------------------
   --  @Procedure: Resolve
   --  @Description: Resolves all links to symbols, if possible.
   procedure Resolve;

   --  ------------------------------------------------------------------------
   --  @Type: Entry_Types
   --  @Purpose:
   --    The symbol table consists of entries, whereby an entry consists of the
   --    symbol and additional information about it. If only a link to a (yet)
   --    unknown symbol is known, the symbol part of the entry is left empty.
   type Entry_Type is record
      --  An entry of the table contains the symbol itself
      Symb    : Symbol.Symbol_Type;
      --  The link to this symbol
      Link    : ASU.Unbounded_String;
      --  All used packages at the position of the symbol
      Context : String_Vector.Vector;
      --  The html parts of the symbol
      Parts   : Parts_Vector.Vector;
   end record;

   --  ------------------------------------------------------------------------
   --  @Function: "="
   --  @Description:
   --    Defines, that two entries of the symbol table are equal, if their
   --    containing symbols are equal.
   --  @Parameter:
   --    +Left: One of the entries to check the equality with another one
   --    +Right: The other entry to check the equality with
   --  @Return:
   --    True, if the two symbols of the entries are equal.
   function "=" (Left, Right : Entry_Type) return Boolean;
   pragma Inline ("=");

   package Entries_Type is new Ada.Containers.Vectors
     (Index_Type => Natural,
      Element_Type => Entry_Type,
      "=" => "=");
   Entries : Entries_Type.Vector;

end Symbol_Table;
